<template>
  <div class="container">
    <el-dialog
      title="题目预览"
      :visible="dialogVisible"
      width="60%"
      @close="handleClose"
    >
      <el-descriptions :column="4">
        <el-descriptions-item label="【题型】">{{cQuestionType}}</el-descriptions-item>
        <el-descriptions-item label="【编号】">{{id}}</el-descriptions-item>
        <el-descriptions-item label="【难度】">{{cDifficulty}}</el-descriptions-item>
        <el-descriptions-item label="【标签】">{{previewData.tags}}</el-descriptions-item>
        <el-descriptions-item label="【学科】">{{previewData.subjectName}}</el-descriptions-item>
        <el-descriptions-item label="【目录】">{{previewData.directoryName}}</el-descriptions-item>
        <el-descriptions-item label="【方向】">{{previewData.direction}}</el-descriptions-item>
      </el-descriptions>
      <hr />
      <span>【题干】：</span>
      <p style="color: blue" v-html="previewData.question"></p>
      <span>{{cTitle}}</span>
      <div class="radio-css">
        <div v-if="previewData.questionType==='1'">
          <p v-for="item in previewData.options" :key="item.id">
            <el-radio :value="item.isRight===1?item.code:''" :label="item.code">{{item.title}}</el-radio>
          </p>
        </div>
        <div v-else-if="previewData.questionType==='2'">
          <p v-for="item in previewData.options" :key="item.id">
            <el-checkbox :value="item.isRight===1?true:false">{{item.title}}</el-checkbox>
          </p>
        </div>

      </div>
      <hr>
      <p>【参考答案】：<el-button type="danger" size="small" @click="videoShow=true">视频答案预览</el-button></p>
      <div class="video" v-if="videoShow">
        <video controls :src="previewData.videoURL"></video>
      </div>
      <hr>
      <p>【答案解析】：{{previewData.answerID}}</p>
      <hr>
      <p>【题目备注】：{{previewData.remarks}}</p>
      <span slot="footer" class="dialog-footer">
        <el-button type="primary" @click="close">关闭</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { detail } from '@/api/hmmm/questions.js'
export default {
  data () {
    return {
      previewData: {
        questionType: '', // 题型
        difficulty: '', // 难度
        tags: '', // 标签
        subjectName: '', // 学科
        directoryName: '', // 目录
        direction: '', // 方向
        question: '', // 题干
        options: [], // 题的选项
        answerID: '', // 答案解析
        remarks: '', // 题目备注
        videoURL: ''
      },
      videoShow: false

    }
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    id: {
      type: Number
    }
  },
  methods: {
    close () {
      this.videoShow = false
      this.previewData = {
        questionType: '', // 题型
        difficulty: '', // 难度
        tags: '', // 标签
        subjectName: '', // 学科
        directoryName: '', // 目录
        direction: '', // 方向
        question: '', // 题干
        options: [], // 题的选项
        answerID: '', // 答案解析
        remarks: '', // 题目备注
        videoURL: ''
      }
      this.$emit('update:dialogVisible', false)
    },
    handleClose () {
      this.close()
    },
    async getDetail () {
      const { data } = await detail({ id: this.id })
      this.previewData = data
    },
    questionTypeZH () {
      const questionType = this.previewData.questionType
      let result = ''
      if (questionType === '1') {
        result = '单选'
      } else if (questionType === '2') {
        result = '多选'
      } else if (questionType === '3') {
        result = '简答'
      }
      return result
    },
    difficultyZH () {
      const difficulty = this.previewData.difficulty
      let result = ''
      if (difficulty === '1') {
        result = '简单'
      } else if (difficulty === '2') {
        result = '一般'
      } else if (difficulty === '3') {
        result = '困难'
      }
      return result
    }
  },
  computed: {
    // 题型转化中文
    cQuestionType () {
      return this.questionTypeZH()
    },
    // 题型转化中文
    cDifficulty () {
      return this.difficultyZH()
    },
    // 提示拼接
    cTitle () {
      return this.questionTypeZH() + '题 选项: （以下选中的选项为正确答案）'
    }
  }
}
</script>

<style scoped>
.radio-css{
  line-height: 25px;
}

::v-deep .el-dialog__footer {
  text-align: right;
}

::v-deep .el-descriptions-item__label:not(.is-bordered-label) {
    align-items: center;
    margin: 0;
}

.video{
  width: 400px;
  height: 300px;
}
video{
  width: 100%;
  height: 100%;
}

</style>
